﻿using FastColoredTextBoxNS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;


namespace NPCScriptEditor.Windows
{
    public partial class wineditor : Form
    {
        AutocompleteMenu menu;
        public wineditor(string code)
        {
            InitializeComponent();
            fastColoredTextBox1.Language = Language.JS;
            string[] snippets = { "function damaged(e)\n{^\n}",
                "function init(e)\n{^\n}","function interact(e)\n{^\n}","function dialog(e)\n{^\n}","function died(e)\n{^\n}","function kill(e)\n{^\n}",
                "com.company.Class1.Method1",
                "if(^)\n{\n}", "if(^)\n{\n}\nelse\n{\n}", "for(^;;)\n{\n}", "while(^)\n{\n}", "do${\n^}while();", "switch(^)\n{\n\tcase : break;\n}" };




            menu = new AutocompleteMenu(this.fastColoredTextBox1)
            {
                MinFragmentLength = 2
            };
            var items = new List<AutocompleteItem>();

            foreach (var item in snippets)
                items.Add(new SnippetAutocompleteItem(item) { ImageIndex = 1 });

            //设置为自动完成源  
            // view.SetAutocompleteItems(items);
            // menu.
            menu.Items.SetAutocompleteItems(items);
            menu.Items.MaximumSize = new System.Drawing.Size(200, 300);
            menu.Items.Width = 200;

        }

        private void wineditor_Load(object sender, EventArgs e)
        {

        }

        private void wineditor_KeyDown(object sender, KeyEventArgs e)
        {
            var m = ModifierKeys;
            //Debug.WriteLine("按下");
            if ((m & Keys.Control) == Keys.Control
                && (m & Keys.Alt) == Keys.Alt)
                MessageBox.Show("Ctrl+Alt!");
            if (e.KeyData == Keys.K && m.CompareTo(Keys.Control)==0)
            {
                Debug.WriteLine("按下1");
                //forced show (MinFragmentLength will be ignored)
                menu.Show(true);
                e.Handled = true;
            }
            else if (e.Control && e.KeyValue == (int)Keys.Z)
            {
                Debug.WriteLine("按下2");
                Clipboard.SetText(
                    this.fastColoredTextBox1.Text);
                e.Handled = true;
            }
            else if (e.KeyData == Keys.X && e.Modifiers == Keys.Control)
            {
                Debug.WriteLine("按下3");
                fastColoredTextBox1.Text =
                   Clipboard.GetText();
                e.Handled = true;

            }
        }

        private void wineditor_FormClosing(object sender, FormClosingEventArgs e)
        {

        }
            

        private void fastColoredTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            Debug.WriteLine(e.KeyData);
            Debug.WriteLine((int)Keys.Z );
        }
    }
}
